<?
require_once ("library/Settings.php");
require_once ('library/banks/FileData.php');

function GetPageFileBlock($file)
{
	$out = '';
	$page = array();


	$data = GetFileDataById($file);
	$uploaderProfile = GetUserDataById($data[0]['uploader']);
	$out .= '<div class="center-module single-file">';
	$out .= '<div class="title">'.GetFileLink($data[0]['title'],$data[0]).'</div>';
	$out .= '<div class="stats">'.$data[0]['description'].'</div><br>';
	$out .= '<div class="uploader">Uploaded by <a class="profile" href="?type=profile&page='.$uploaderProfile[0]['id'].'">'.$uploaderProfile[0]['name'].'</a> on <b>'.date("l dS F Y", $data[0]['time']).'</b> in <b>'.GetCategoryName($data[0]['category']).'</b></div>';
	$out .= '<div class="stats">Times downloaded: '.$data[0]['downloads'].'</div>';
	$out .= '<br>'.GetFileLink('Download Now', $data[0]);
	$out .= '</div>';
	return $out;
}

function GetFileDownloadBlock($file)
{
	$out = '';
	$page = array();


	$data = GetFileDataById($file);
	$uploaderProfile = GetUserDataById($data[0]['uploader']);
	$out .= '<div class="center-module single-file">';
	$out .= '<div class="title">'.$data[0]['title'].'</div>';
	$out .= '<div class="uploader">Uploaded by <a class="profile" href="?type=profile&page='.$uploaderProfile[0]['id'].'">'.$uploaderProfile[0]['name'].'</a></div>';
	$out .= '<div class="stats">Downloads:'.$data[0]['downloads'].'</div>';
	$out .= '</div>';
	return $out;
}

function GetLoginBlock($g_user,$p_asswd)
{
	$logged_in = CheckLogin($g_user,$p_asswd);
	$out = '';

	if($logged_in > 0)
	{
	}
	else
	{

	}
}

function GetUploadPage()
{
	$out .= '<div class="center-module">';
	$out .= '<div class="title">Share a File</div>';
	$out .= '<form name="login" enctype="multipart/form-data" action="index.php?type=upload" method="post">';
	$out .= 'File: <input type="file" name="notesfile"><br><br>';
	$out .= 'File Title: <input type="text" name="filetitle"><br><br>';
	//$out .= 'Lecture Title: <input type="text" name="lecturetitle"><br>';
	//$out .= 'Date of Lecture: <input type="text" name="lecturedate"><br>';
	$out .= 'File Description: <input type="text" name="filedesc"><br><br>';
	$out .= 'Subject: <select name="filecategory">';
	$c = GetCategoryNames();
	foreach ($c as $a)
	{
		$out .= '<option value="'.$a['id'].'">'.$a['name'].'</option>';
	}
	$out .= '</select><br>';
	$out .= '<input type="submit" value="Share"></form><br>';
	$out .= '<br><br>';
	$out .= '</div>';
	return $out;
}

function GetPageProfileBlock($pid)
{
	$data = GetUserDataById($pid);
	$out .= '<div class="center-module single-file">';
	$out .= '<div class="title">Profile: '.$data[0]['handle'].'</div>';
	$out .= '<div class="user-data"><b>Name:</b> '.$data[0]['name'].' '.$data[0]['surname'].'</div>';
	$out .= '<div class="user-data"><b>E-mail:</b> '.$data[0]['email'].'</div>';
	$out .= '<div class="user-data"><b>Notes Uploaded:</b> '.$data[0]['uploads'].'</div>';
	$out .= '</div>';
	return $out;
}
function GetBigFileBlock($cat,$small=false)
{
	return GetBigFileBlockNum($cat, 0, $small);
}

function GetBigFileBlockNum($cat, $num,$small=false)
{
	$page = array();
	$out = '';

	$extra = '';
	if ($num > 0) $extra = ' LIMIT 0,'.$num;
	switch($cat) 
	{
		case -1:
			$title = 'All Notes';
			break;
		case -2:
			$title = 'Recent Notes';
			break;
		case -3:
			$title = 'Top Downloads';
			break;
		default:
			$title = GetCategoryName($cat);
			break;
	}
	
	$page['title'] = $title;
	$page['content'] = GetFileDataByCategory($cat,$num);
	
	//Begin Output
	if (!$small) 
	{
		$out .= '<div class="center-module">';
	}
	else
	{
		$out .= '<div class="right-module">';
	}
	$out .= '<div class="title">'.$page['title'].'</div>';
	$i = 0;
if($small) $out .= '<ul>';
	foreach ( $page['content'] as $file )
	{
	$i++;
		if (!$small) 
		{
			$out .= GetFileBox($file);
		}
		else
		{
			
			$out .= GetFileName($file);

		}
	}
if($small) $out .= '</ul>';
	$out .= '</div>';
	return $out; 
}


function GetFileBox($file)
{
	$out = '';
	$uploaderProfile = GetUserDataById($file['uploader']);
	$out .= '<div class="filebox">';
//	$out .= '<a href="notes/'.$file['file'].'" class="file-link">'.$file['title'].'</a>&nbsp;&nbsp;<div class="uploader">Uploaded by <a class="profile" href="?type=profile&page='.$uploaderProfile[0]['id'].'">'. $uploaderProfile[0]['name'] .'</a>.</div>';
	$out .=  GetFileLink($file['title'],$file);
	$out .= '&nbsp;&nbsp;<div class="uploader">Uploaded by <a class="profile" href="?type=profile&page='.$uploaderProfile[0]['id'].'">'. $uploaderProfile[0]['name'] .'</a>.</div>';
	$out .= '<br><div class="file-desc">'.$file['description'].' <a class="more" href="?type=file&page='.$file['id'].'">[more]</a></div>'; 	
	$out .= '</div>';
	return $out;
}

function GetFileName($file)
{
	$out = '';
	$uploaderProfile = GetUserDataById($file['uploader']);
	$out .= '<li><div class="filename">';
	$out .= GetFileLink($file['title'],$file).' <a class="more" href="?type=file&page='.$file['id'].'">[more]</a>'; 	
	$out .= '</div></li>';
	return $out;
}

function GetFileLink($text,$file)
{
	return '<a href="#" onclick="window.open(\'download.php?fileid='.$file['id'].'\',\'dlwin\',\'width=360,height=280,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no\')" class="file-link">'.$text.'</a>';
}

function TopSharersBlock($limit)
{
	$list = GetTopSharers($limit);
	$out = '';
	$out .= '<div class="right-module">';	
	$out .= '<div class="title">Thanks!</div>';
	foreach ($list as $l)
	{
		$out .= '<div class="username">';
		$out .= '<a href="?type=profile&page='.$l['name'][0]['id'].'" class="profile">'.$l['name'][0]['name'].' '.$l['name'][0]['surname'].'</a> ('.$l['count'].' files)</a>'; 	
		$out .= '</div>';			
	}
	$out .= '</div>';
	return $out;
}
?>
